<template>
  <div class="personnel-overview">
    <el-row :gutter="20">
      <!-- 部门分布卡片 -->
      <el-col :span="8">
        <el-card class="department-card">
          <template #header>
            <div class="card-header">
              <span>部门分布</span>
            </div>
          </template>
          <div class="chart-container">
            <!-- 这里将添加部门分布饼图 -->
          </div>
        </el-card>
      </el-col>

      <!-- 人员类型卡片 -->
      <el-col :span="8">
        <el-card class="type-card">
          <template #header>
            <div class="card-header">
              <span>人员类型</span>
            </div>
          </template>
          <div class="chart-container">
            <!-- 这里将添加人员类型饼图 -->
          </div>
        </el-card>
      </el-col>

      <!-- 年龄分布卡片 -->
      <el-col :span="8">
        <el-card class="age-card">
          <template #header>
            <div class="card-header">
              <span>年龄分布</span>
            </div>
          </template>
          <div class="chart-container">
            <!-- 这里将添加年龄分布柱状图 -->
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 人员列表 -->
    <el-card class="personnel-list">
      <template #header>
        <div class="list-header">
          <span>人员列表</span>
          <el-input
            v-model="searchQuery"
            placeholder="搜索人员"
            class="search-input"
          >
            <template #prefix>
              <el-icon><Search /></el-icon>
            </template>
          </el-input>
        </div>
      </template>
      
      <el-table :data="filteredPersonnel" style="width: 100%">
        <el-table-column prop="id" label="工号" width="100" />
        <el-table-column prop="name" label="姓名" width="120" />
        <el-table-column prop="department" label="部门" width="120" />
        <el-table-column prop="position" label="职位" width="120" />
        <el-table-column prop="type" label="类型" width="120" />
        <el-table-column prop="entryDate" label="入职日期" width="120" />
        <el-table-column prop="status" label="状态">
          <template #default="scope">
            <el-tag :type="scope.row.status === '在职' ? 'success' : 'danger'">
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { Search } from '@element-plus/icons-vue'

const searchQuery = ref('')
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(100)

// 模拟人员数据
const personnel = ref([
  {
    id: '001',
    name: '张三',
    department: '研发部',
    position: '工程师',
    type: '全职',
    entryDate: '2023-01-01',
    status: '在职'
  },
  // 更多数据...
])

const filteredPersonnel = computed(() => {
  return personnel.value.filter(item =>
    Object.values(item).some(val =>
      val.toString().toLowerCase().includes(searchQuery.value.toLowerCase())
    )
  )
})

const handleSizeChange = (val) => {
  pageSize.value = val
}

const handleCurrentChange = (val) => {
  currentPage.value = val
}
</script>

<style scoped>
.personnel-overview {
  padding: 20px;
}

.card-header {
  font-weight: bold;
}

.chart-container {
  height: 300px;
}

.personnel-list {
  margin-top: 20px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-input {
  width: 200px;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style> 